//
//  HMUserAccount.swift
//  Faner_Weibo
//
//  Created by 范英强 on 16/1/29.
//  Copyright © 2016年 范英强. All rights reserved.
//

import UIKit

class HMUserAccount: NSObject ,NSCoding{
    
    var access_token: String?
    //过期时间
    var expires_in: NSTimeInterval = 0{
        didSet{
            expiresDate = NSDate(timeIntervalSinceNow: expires_in)
            print(expiresDate)
        }
    }
    var expiresDate: NSDate?
    var remind_in: String?
    var uid:String?
    var avatar_large: String?
    var screen_name: String?
        
    init(dict:[String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    }
    
    override var description: String {
        let key = ["access_token","expires_in","remind_in","uid"]
        return dictionaryWithValuesForKeys(key).description
    }
    
    // MARK: - 归档
    
    //解档 从文件里读取
    required init?(coder aDecoder: NSCoder) {
        access_token = aDecoder.decodeObjectForKey("access_token") as? String
        expiresDate = aDecoder.decodeObjectForKey("expiresDate") as? NSDate
        uid = aDecoder.decodeObjectForKey("uid") as? String
        avatar_large = aDecoder.decodeObjectForKey("avatar_large") as? String
        screen_name = aDecoder.decodeObjectForKey("screen_name") as? String
    }
    //归档 把对象转成二进制文件 保存
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(access_token, forKey: "access_token")
        aCoder.encodeObject(expiresDate, forKey: "expiresDate")
        aCoder.encodeObject(uid, forKey: "uid")
        aCoder.encodeObject(avatar_large, forKey: "avatar_large")
        aCoder.encodeObject(screen_name, forKey: "screen_name")
    }

}
